package com.ccb.jyzx.expand.tiantouonline.controller;

import com.alibaba.fastjson.JSON;
import com.ccb.jyzx.expand.tiantouonline.service.FileHistoryService;
import com.ccb.jyzx.expand.tiantouonline.utils.ParseDateUtils;
import com.ccb.jyzx.expand.tiantouonline.view.request.FileHistoryInfoPageRequestBody;
import com.ccb.jyzx.expand.tiantouonline.view.response.FileHistoryInfo;
import com.ccb.jyzx.expand.tiantouonline.view.response.PageResponseReult;
import com.ccb.jyzx.expand.tiantouonline.view.response.PageResult;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

/**
 * @author XIEFEI
 * @date 2019-11-22 15:19
 * @Description 文件上传历史查询
 **/
@Controller
@RequestMapping("/tto/history")
@Api(tags = "文件上传历史查询")
public class FileHistoryController {

    @Autowired
    FileHistoryService fileHistoryService;




    @ResponseBody
    @PostMapping(value = "getPageList",consumes = "application/json;charset=UTF-8")
    public PageResponseReult<FileHistoryInfo> getPageList(@RequestBody FileHistoryInfoPageRequestBody page){


        if (page.getDateRang()!=null&&page.getDateRang().length>0){
            if (page.getDateRang().length==1){
                Date start = page.getDateRang()[0];
                String day = ParseDateUtils.DAY_FOMAT.format(start);
                String startString = day+"000000";
                String endString=day+"235959";
                page.setStartTime(Long.valueOf(startString));
                page.setEndTime(Long.valueOf(endString));
            }else if(page.getDateRang().length==2){
                Date start = page.getDateRang()[0];
                Date end = page.getDateRang()[1];
                long startLong = Long.valueOf(ParseDateUtils.DAY_FOMAT.format(start) + "000000");
                long endLong = Long.valueOf(ParseDateUtils.DAY_FOMAT.format(end) + "235959");

                page.setStartTime(startLong);
                page.setEndTime(endLong);
            }
        }
        return fileHistoryService.findByPageParam(page);
    }
}
